/*
 * For legal stuff see the file COPYRIGHT
 */
#import "ColCell.h"

/* Font info */
static NXCoord ascender, descender, lineHeight;

@implementation ColCell

- (void)setCellData:(id <ColCellData>)obj
{
  [self setStringValue:""];
  data = obj;
}

- (id <ColCellData>)cellData
{
  return data;
}

- setFont:fontObj
{
  [super setFont:fontObj];
  /*
   * save this info so we don't have to look it up every time we draw
   * Note:  support for a TextCell is a font object
   */
  NXTextFontInfo(support, &ascender, &descender, &lineHeight);
  return self;
}    

/*
 * Override the drawing method to put the data in two columns
 */
- drawInside:(const NXRect *)cellFrame inView:controlView
{
  NXCoord baseX, baseY;
  ColDesc *colDesc = [data colDesc];

  baseX = NX_X(cellFrame);
  baseY = NX_Y(cellFrame) + lineHeight - descender;

  [super drawInside:cellFrame inView:controlView];
  PSsetgray(NX_BLACK);

  if ( colDesc ) {
    for ( ; colDesc->method; colDesc++ ) {
      PSmoveto( baseX + colDesc->offset, baseY );
      PSshow( (const char *)[(id)data perform:colDesc->selector] );
    }
  }

  return self;
}

- copyFromZone:(NXZone *)zone
{
  ColCell *copy;

  copy = [super copyFromZone:zone];
  copy->data = data;
  return copy;
}

@end
